#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, p, ans[200001] = {0};
    int sum = -9999999;
    cin >> p;
    for (int i = 1; i <= p; i++)
    {
        cin >> n;
        ans[i] = max(ans[i - 1] + n, n);
        sum = max(sum, ans[i]);
    }
    cout << sum;
    return 0;
}